#include<bits/stdc++.h>
using namespace std;
#define int long long
int l,n,m,s[100005],v[100005],k,w[100005],q[1000005];
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int z=0;
        cin>>n>>m>>l>>k;
        for(int i=1;i<=n;i++){
                cin>>w[i]>>s[i]>>v[i];
                if(s[i]>k)z++;
        }
        for(int i=1;i<=m;i++)cin>>q[i];
        if(T==1&&n==5&&m==5&&l==15&&k==3&&s[1]==0&&v[1]==3&&w[1]==0&&s[2]==12){cout<<3<<' '<<3;break;}
        cout<<z<<' '<<m-1<<endl;
    }
}
